package com.verlet.springbootdemo.simple.nettyrpc.client.codec;

import com.verlet.springbootdemo.simple.nettyrpc.RpcResult;
import com.verlet.springbootdemo.util.ObjectMapperUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

/**
 * RpcResult 解码器
 *
 * @author Verlet
 * @date 2023-08-22 20:13
 */
public class RpcResultDecoder extends MessageToMessageDecoder<String> {
    @Override
    protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
        RpcResult bean = ObjectMapperUtils.toBean(msg, RpcResult.class);
        if (bean != null) {
            out.add(bean);
        }
    }
}
